﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Web.Services;
using BLL;
using NS.Utilities;
using NS.BLL.Systems;

public partial class Platform_OrderRefund : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            InitData();
            GridBind();
        }
    }
    private void InitData()
    {
        ListItem li = new ListItem("待退款", "7");
        ddlState.Items.Insert(0, li);
        li = new ListItem("已退款", "8");
        ddlState.Items.Insert(1, li);
    }
    public void GridBind()
    {
        FGridView1.SQLString = OrderService.GetAllOrder_SQL(ddlState.SelectedValue, Mobile.Text.Trim(), OrderNo.Text.Trim());
        FGridView1.PKey = "OrderID";
        FGridView1.OrderName = "PayDate";
        FGridView1.BindData();
        FGridView1.AddControl();
    }
    protected void FGridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex >= 0)
        {
            string orderNo = ((HiddenField)e.Row.FindControl("HiddOrderNo")).Value;
            decimal Refund = MemberAccountService.GetRefund(orderNo);
            if (Refund > 0)
            {
                ((Label)e.Row.FindControl("labRes")).Visible = true;
            }
            else
            {
                ((Button)e.Row.FindControl("btnRefund")).Visible = true;
            }
        }
    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        GridBind();
    }
    protected void btnRefund_Click(object sender, EventArgs e)
    {
        string orderID = ((Button)sender).CommandArgument.ToString();
        string res = OrderService.Refund(orderID);
        if (!string.IsNullOrEmpty(res))
        {
            MessageBox.ShowInfo(this, res);
        }
        GridBind();
    }
}